package com.example.rumen;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.bumptech.glide.Glide;

import java.util.Objects;


public class Login2 extends AppCompatActivity {

    private EditText username_text;
    private EditText password_text;
    private Button btn_cancle;
    private Button btn_login;
    private String password;
    private String username;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
       
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_login2);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);

            return insets;
        });

        /*
        实现动图
        * */
        ImageView image_wiev = findViewById(R.id.imageView);
        Glide.with(this).asGif().load(R.drawable.longm).into(image_wiev);



        /*登录*/
        username_text = findViewById(R.id.editText_user);
        password_text = findViewById(R.id.editText_pass);
        btn_login = findViewById(R.id.button_login);
        btn_cancle = findViewById(R.id.button_cancle);

        btn_login.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {
                username = username_text.getText().toString();
                password = password_text.getText().toString();

                if (Objects.equals("jw", username) && Objects.equals("123123", password)) {
                    Toast.makeText(getApplicationContext(), "成功登录", Toast.LENGTH_SHORT).show();
                    //【加分点】登录成功后跳转到Btns的页面，然后清空输入框
                    Intent intent = new Intent((getApplicationContext()),Btns.class);
                    password_text.setText("");
                    username_text.setText("");
                    password_text.requestFocus();
                    password_text.requestFocus();
                    startActivity(intent);
                }


                if (!Objects.equals("lh", username) && Objects.equals("123123", password)) {
                    Toast.makeText(getApplicationContext(), "用户名错误", Toast.LENGTH_SHORT).show();
                    username_text.setText("");
                    username_text.requestFocus();
                }


                if (Objects.equals("lh", username) && !Objects.equals("123123", password)) {
                    Toast.makeText(getApplicationContext(), "密码错误", Toast.LENGTH_SHORT).show();
                    password_text.setText("");
                    password_text.requestFocus();
                }


                if (!Objects.equals("lh", username) && !Objects.equals("123123", password)) {
                    Toast.makeText(getApplicationContext(), "用户名和密码都错误", Toast.LENGTH_SHORT).show();
                    password_text.setText("");
                    username_text.setText("");
                    password_text.requestFocus();
                    password_text.requestFocus();
                }
            }
        });

    }

 /*   @Override
    protected void onResume() {
        super.onResume();
        // 清空用户名和密码输入框
        if (username_text != null && password_text != null) {
            username_text.setText("");
            password_text.setText("");
        }
    }*/
}